<script lang="ts" setup>
import type { RankedInfoFormat } from '@/types/ranked'
import RankedDisplay from '@/components/rankedDisplay.vue'
import { getRankInfo } from '@/LcuApi/rankInfo'
import { ref } from 'vue'
import { useI18n } from 'vue-i18n';

const { t } = useI18n()

const loading = ref(false)
// 获取指定召唤师的段位信息
const rankData = ref<RankedInfoFormat>({})
async function getRankedStats(puuid) {
  loading.value = true
  rankData.value = await getRankInfo(puuid)
  loading.value = false
}

defineExpose({ getRankedStats })
</script>

<template>
  <div class="rank_info h-full flex flex-col">
    <a-spin :loading="loading" class="rank_box solo_rank">
      <div class="rank_icon">
        <RankedDisplay :tier="rankData?.solo?.tier" />
      </div>
      <div class="rank_info">
        <p>{{ rankData?.solo?.text }}</p>
        <div class="flex items-center w-80%">
          <a-progress :percent="rankData?.solo?.lp / 100" color="#2A7C8C" class="my-8px" :stroke-width="5" animation
            :show-text="false" />
          <p class="rank_point text-10px ml-8px opacity-50">
            <span class="mr-2px">{{ rankData?.solo?.lp }}</span>
            {{ t(`RankedTable.LP`) }}
          </p>
        </div>
        <p>{{ t(`RankedTable.cumWins`) }}：{{ rankData?.solo?.wins }}</p>
        <p>{{ t(`RankedTable.highestTier`) }}：{{ rankData?.solo?.highestText }}</p>
      </div>
      <div class="rank_mode">{{ t(`RankedTable.solo`) }}</div>
      <div class="rank_mode_eng">SOLO/DUO</div>
    </a-spin>
    <a-spin :loading="loading" class="rank_box flex_rank">
      <div class="rank_icon">
        <RankedDisplay :tier="rankData?.flex?.tier" />
      </div>
      <div class="rank_info">
        <p>{{ rankData?.flex?.text }}</p>
        <div class="flex items-center w-80%">
          <a-progress :percent="rankData?.flex?.lp / 100" color="#2A7C8C" class="my-8px" :stroke-width="5" animation
            :show-text="false" />
          <p class="rank_point text-10px ml-8px opacity-50">
            <span class="mr-2px">{{ rankData?.flex?.lp }}</span>
            {{ t(`RankedTable.LP`) }}
          </p>
        </div>
        <p>{{ t(`RankedTable.cumWins`) }}：{{ rankData?.flex?.wins }}</p>
        <p>{{ t(`RankedTable.highestTier`) }}：{{ rankData?.flex?.highestText }}</p>
      </div>
      <div class="rank_mode">{{ t(`RankedTable.flex`) }}</div>
      <div class="rank_mode_eng">FLEX</div>
    </a-spin>
  </div>
</template>

<style lang="scss" scoped>
.rank_info {
  .rank_box {
    flex: 1;
    width: 100%;
    position: relative;
    background-color: var(--module-bg-color);
    border-radius: var(--module-border-radius);
    box-shadow: var(--module-box-shadow);
    display: flex;
    align-items: center;
    padding-left: 10%;

    .rank_icon {
      height: 100px;
      width: 100px;
    }

    .rank_info {
      margin: 0 0 0 10px;
      width: 120px;
      font-size: 13px;
      line-height: 1.4;
      font-weight: bold;
      opacity: 0.7;
    }

    .rank_mode {
      position: absolute;
      top: 12px;
      right: 14px;
      font-size: 13px;
      text-align: right;
      font-weight: bold;
      opacity: 0.7;
    }

    .rank_mode_eng {
      position: absolute;
      writing-mode: vertical-rl;
      top: 50%;
      right: 4px;
      transform: translateY(-50%) rotate(180deg);
      font-size: 10px;
      opacity: 0.3;
      font-weight: bolder
    }

    &+.rank_box {
      margin-top: 15px;
    }
  }
}
</style>
